package com.talent.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.talent.dao.CourseMapper;
import com.talent.dao.ScheduleMapper;
import com.talent.dao.TrainDetailMapper;
import com.talent.pojo.Schedule;
import com.talent.service.ScheduleService;
import com.talent.vo.ScheduleVo;
import com.talent.vo.TrainDetailVo;
@Service
public class ScheduleServiceImpl implements ScheduleService{
@Autowired
private ScheduleMapper scheduleMapper;
@Autowired
private CourseMapper courseMapper;
	@Override
	public List<ScheduleVo> selectVoByPrimaryKey(Integer id) {
		return scheduleMapper.selectVoByPrimaryKey(id);
	}
	@Override
	public ScheduleVo selectVoByPrimaryKey1(Integer id) {
		return scheduleMapper.selectVoByPrimaryKey1(id);
	}
	@Override
	public ScheduleVo selectVoByTrainDetailId(Integer trainDetailId) {
		return scheduleMapper.selectVoByTrainDetailId(trainDetailId);
	}
	@Override
	public void updateStatus(Integer id, int sta) {
		scheduleMapper.updateStatus(id,sta);
	}
	@Override
	public void updateSuggestion(int id, String suggestion) {
		scheduleMapper.updateSuggestion(id,suggestion);
	}
	@Override
	public void add(String[] courseName, Double[] score, Double[] theory, Double[] experiment, Double[] selfmaster,
			String[] examtype, Integer[] termth) {
		for(int i = 0; i < courseName.length; i++){
			Integer courseId = courseMapper.selectIdByCourseName(courseName[i]);
			Schedule schedule = new Schedule();
			schedule.setCourseId(courseId);
			schedule.setScore(score[i]);
			schedule.setTheory(theory[i]);
			schedule.setExperiment(experiment[i]);
			schedule.setSelfmaster(selfmaster[i]);
			schedule.setTerm(termth[i]);
			schedule.setExamtype(examtype[i]);
			schedule.setStatus(0);
			scheduleMapper.insert(schedule);
		}
	}
	@Override
	public List<Schedule> selectScheduleId(int length) {
		return scheduleMapper.selectTopId(length);
	}
	@Override
	public void deleteByTrainDetailId(List<TrainDetailVo> tds) {
		for(int i = 0; i<tds.size(); i++){
			scheduleMapper.deleteByTrainDetailId(tds.get(i).getId());
		}
	}
	@Override
	public void edit(Integer scheduleId, Integer theorystartweek, Integer theoryendweek, Integer expstartweek,
			Integer expendweek, String theoryteacher, String expteacher) {
		Schedule schedule = scheduleMapper.selectByPrimaryKey(scheduleId);
		schedule.setTheorystartweek(theorystartweek);
		schedule.setTheoryendweek(theoryendweek);
		schedule.setExpstartweek(expstartweek);
		schedule.setExpendweek(expendweek);
		schedule.setTheoryteacher(theoryteacher);
		schedule.setExpteacher(expteacher);
		scheduleMapper.updateByPrimaryKeySelective(schedule);
	}

}
